package cn.luischen.service.content.impl;

import cn.luischen.constant.ErrorConstant;
import cn.luischen.constant.Types;
import cn.luischen.constant.WebConst;
import cn.luischen.dao.CommentDao;
import cn.luischen.dao.ContentDao;
import cn.luischen.dao.RelationShipDao;
import cn.luischen.dto.cond.ContentCond;
import cn.luischen.dto.cond.MetaCond;
import cn.luischen.exception.BusinessException;
import cn.luischen.model.CommentDomain;
import cn.luischen.model.ContentDomain;
import cn.luischen.model.RelationShipDomain;
import cn.luischen.service.content.ContentService;
import cn.luischen.service.meta.MetaService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.junit.rules.ExpectedException;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
import java.lang.reflect.Method;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.ParserConfig;
import java.util.Map;
import java.util.List;
import com.unitspirit.runtime.*;

/**
 * The class contains tests for the class cn.luischen.service.content.impl.ContentServiceImpl.
 *
 * @generatedBy UnitSpirit CreateTemplateTestFile4
 * @version 1.0.9.11 
 */
@PowerMockIgnore({ "javax.management.*" })
@RunWith(PowerMockRunner.class)
@PrepareForTest({ cn.luischen.dao.ContentDao.class })
public class ContentServiceImpl_getArticlesByCond_WGTest {
	@Rule
	public ExpectedException unitspirit_thrown = ExpectedException.none();

	/**
	 * 测试方法初始化.
	 * 
	 * @throws Exception 
	 *         if the initialization fails for some reason 
	 *  
	 * @generatedBy UnitSpirit at 2021-12-06 21:50:30
	 */
	@org.junit.Before
	public void setUp() throws Exception {
		try {
			GlobalUnitInit.init();
			MockitoAnnotations.initMocks(this);
			ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	@InjectMocks
	cn.luischen.service.content.impl.ContentServiceImpl unitspirit_fixture;

	@Mock
	cn.luischen.dao.ContentDao mock_ContentDao;
	@Mock
	cn.luischen.dao.CommentDao mock_CommentDao;
	@Mock
	cn.luischen.dao.RelationShipDao mock_RelationShipDao;
	@Mock
	cn.luischen.service.meta.MetaService mock_MetaService;

	/**
	 * @date 2021-12-06 21:50:31
	 * @see cn.luischen.service.content.impl.ContentServiceImpl#getArticlesByCond
	 * @category null  
	 * @author null  
	 */
	@Test
	public void test_getArticlesByCond_20211109_110223_933_2_01()
			throws Throwable {
		//被测函数参数定义
		cn.luischen.dto.cond.ContentCond ContentCond_p_0 = JSON.parseObject(
				"{\"type\":\"photo\"}", cn.luischen.dto.cond.ContentCond.class);
		int int_p_1 = 1;
		int int_p_2 = 12;
		//成员变量设置

		//返回值定义 
		String result_expected = "{\"navigatepageNums\":[1],\"startRow\":1,\"hasNextPage\":false,\"prePage\":0,\"nextPage\":0,\"endRow\":1,\"pageSize\":12,\"list\":[{\"created\":1616027687,\"modified\":0,\"allowComment\":1,\"title\":\"test5\",\"type\":\"photo\",\"content\":\"test5test5\",\"cid\":6,\"status\":\"publish\"}],\"pageNum\":1,\"navigatePages\":8,\"navigateFirstPage\":1,\"total\":1,\"pages\":1,\"size\":1,\"isLastPage\":true,\"hasPreviousPage\":false,\"navigateLastPage\":1,\"isFirstPage\":true}";

		java.util.List<cn.luischen.model.ContentDomain> mock_result_Page1 = JSON
				.parseArray(
						"[{\"created\":1616027687,\"modified\":0,\"allowComment\":1,\"title\":\"test5\",\"type\":\"photo\",\"content\":\"test5test5\",\"cid\":6,\"status\":\"publish\"}]",
						cn.luischen.model.ContentDomain.class);

		PowerMockito.when(
				mock_ContentDao.getArticlesByCond(Mockito
						.any(cn.luischen.dto.cond.ContentCond.class)))
				.thenReturn(mock_result_Page1);

		com.github.pagehelper.PageInfo<cn.luischen.model.ContentDomain> unitspirit_result = unitspirit_fixture
				.getArticlesByCond(ContentCond_p_0, int_p_1, int_p_2);
		com.github.pagehelper.PageInfo obj_expected = JSON.parseObject(
				result_expected, com.github.pagehelper.PageInfo.class);
		UnitAssert.assertEquals(
				UnitSpiritFastJsonUtil.getJsonString2(obj_expected),
				UnitSpiritFastJsonUtil.getJsonString2(unitspirit_result));
	}
}
